<template>
  <div class="update-sex">
    <van-picker
        title="标题"
        show-toolbar
        :columns="columns"
        :default-index="sex"
        :value="sex"
        @change="change"
        @cancel="$emit('cancel')"
        @confirm="confirm"
    />
  </div>
</template>

<script>
import { updateProfileInfo } from '@/api/user'
export default {
  name: 'UpdateSex',
  components: {},
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  data () {
    return {
      columns: ['男', '女'],
      sex: this.value
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    async confirm () {
      this.$toast.loading({
        message: '加载中...',
        forbidClick: true, // 静止背景点击
        duration: 0
      })
      try {
        await updateProfileInfo({
          gender: this.sex
        })
        this.$toast.success('修改性别成功')
      } catch (err) {
        this.$toast.fail('修改性别失败')
      }
      this.$emit('input', this.sex)
      this.$emit('cancel')
    },
    change () {
      this.sex = arguments[2]
    }
  }
}
</script>

<style>

</style>
